package thread.produce_customer_base_muti_die;

/**
 * Created by mHandler on 2018/6/2 0002.
 * Description:由于notify的唤醒不确定性造成程序的假死，修改方法把notify改为notifyAll即可，把所有类型的线程唤醒进行竞争即可。
 */
public class Test {

    public static void main(String[] args) throws Exception{
        String lock = "";
        Producer producer = new Producer(lock);
        Customer customer = new Customer(lock);

        ThreadP[] threadP = new ThreadP[2];
        ThreadC[] threadC = new ThreadC[2];
        for (int i = 0; i < 2; ++i){
            threadP[i] = new ThreadP(producer);
            threadP[i].setName("生产者"+i);
            threadC[i] = new ThreadC(customer);
            threadC[i].setName("消费者"+i);
            threadP[i].start();
            threadC[i].start();
        }

        Thread.sleep(5000);
        Thread[] threads = new Thread[Thread.currentThread().getThreadGroup().activeCount()];
        Thread.currentThread().getThreadGroup().enumerate(threads);
        for (int i = 0 ; i < threads.length; ++i){
            System.out.println(threads[i].getName() + " " + threads[i].getState());
        }
    }
}
